<?php
/* [DoYouHaoBaby!] (C)Dianniu From 2010.
   this($)*/

!defined('DYHB_PATH') && exit;

class TemplateGtkGladeWidgetCompiler_GtkImage extends TemplateGtkGladeWidgetCompilerBase{

	protected function compileCreateWidget_(TemplateGtkGladeWidget $oObject){
		$sWidgetClass=$oObject->getWidgetClass();
		$sVariableName='$'.TemplateGtkGlade::getWidgetVariableName($oObject);
		$sCompiled="\t\t{$sVariableName}=new {$sWidgetClass}();";
		if(($Value=$oObject->getProperty('stock'))!==null){// 图片文件
			$sStock=preg_replace('/^gtk-/','',$Value);
			$sStock=str_replace('-','_',$sStock);
			$sStock='Gtk::STOCK_'.strtoupper($sStock);
		}
		else{
			$sStock='Gtk::STOCK_MISSING_IMAGE';
		}
		if(($Value=$oObject->getProperty('icon_size'))!==null){// 图片尺寸
			$sSize=$Value;
		}
		else{
			$sSize='4';
		}
		$sCompiled.= "\t\t{$sVariableName}->set_from_stock({$sStock},{$sSize});";
		$this->setStringInt_($oObject,$sCompiled,'pixel_size',false);// 像素尺寸
		if(($sValue=$oObject->getProperty('xalign'))!==null){// 对齐
			$nXAlign=round(floatval($sValue),2);
		}
		else{
			$nXAlign=0.5;
		}
		if(($sValue=$oObject->getProperty('yalign'))!==null){
			$nYAlign=round(floatval($sValue),2);
		}
		else{
			$nYAlign=0.5;
		}
		$sCompiled.= "\t\t{$sVariableName}->set_alignment({$nXAlign},{$nYAlign});\r\n";
		if(($sValue=$oObject->getProperty('xpad'))!==null){// 留空
			$sXPad=$sValue;
		}
		else{
			$sXPad='0';
		}
		if(($sValue=$oObject->getProperty('ypad'))!==null){
			$sYPad=$sValue;
		}
		else{
			$sYPad='0';
		}
		$sCompiled.= "\t\t{$sVariableName}->set_padding({$sYPad},{$sYPad});";
		return $sCompiled;
	}

	protected function compileChildWidgetPacking_(TemplateGtkGladeWidget $oParentWidget,TemplateGtkGladeWidget $oChildWidget,TemplateGtkGladeWidgetPacking $oPacking){
		 return '';
	}

	static public function regToProcessorManager(ITemplateObjProcessorManager $oManager){
		$oManager->regProcessor(str_replace('TemplateGtkGladeWidgetCompiler_','',__CLASS__),__CLASS__);
	}

}
